/**
 * Created by Administrator on 2017/7/20.
 */
layui.use(['ajaxRequest', 'form'], function (s) {

    var ajaxRequest = layui.ajaxRequest, form = layui.form();
    var url = '/depart/create';
    //获得添加页面
    $(document).on('click', '.add-depart-ment-btn', function () {
        ajaxRequest.addGetHtml(url, '添加部门', 500, 400);
    });
    //添加数据
    $(document).on('click', '.add-depart-ment-sub', function () {
        form.on('submit(department-add)', function (data) {
            var field = data.field, url = '/depart';
            ajaxRequest.ajaxRequest(url, field, 'json', 'post');
        });
        return false;
    });
    //删除数据
    $(document).on('click', '.oa-del-data', function () {
        var id=$(this).attr('data-id'),url='/depart/'+id;
        ajaxRequest.mj_del(url,id,'json','DELETE');
    });
    //编辑
    $(document).on('click','.oa-edit-data',function(){
        var id=$(this).attr('data-id'),url='/depart/'+id+'/edit';
        ajaxRequest.getHtml(url,id,'编辑部门',500,400);
    });
    //保存编辑数据
    $(document).on('click','.edit-depart-ment-sub',function () {
        form.on('submit(department-edit)', function (data) {
            var id=$(this).attr('data-id'),field = data.field, url = '/depart/'+id;
            ajaxRequest.ajaxRequest(url, field, 'json', 'PUT');
        });
        return false;
    });

});